package intelligentcity.model;

public class Point {

    protected int x;
    protected int y;

    public Point(int x, int y) {
        setX(x);
        setY(y);
    }

    public Point(Point point) {
        this(point.getX(), point.getY());
    }

    public synchronized int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public synchronized int getY() {
        return y;
    }

    public synchronized void setY(int y) {
        this.y = y;
    }

    public synchronized void incX() {
        x++;
    }

    public synchronized void decX() {
        x--;
    }

    public synchronized void incY() {
        y++;
    }

    public synchronized void decY() {
        y--;
    }

    public synchronized void incX(int number) {
        for (int i = 0; i < number; i++) {
            x++;
        }
    }

    public synchronized void decX(int number) {
        for (int i = 0; i < number; i++) {
            x--;
        }
    }

    public synchronized void incY(int number) {
        for (int i = 0; i < number; i++) {
            y++;
        }
    }

    public synchronized void decY(int number) {
        for (int i = 0; i < number; i++) {
            y--;
        }
    }

    public synchronized boolean inside(Point upperLeftCorner, Point bottomRightCorner) {
        if (x >= upperLeftCorner.getX() && x <= bottomRightCorner.getX() && y >= upperLeftCorner.getY()
                && y <= bottomRightCorner.getY()) {
            return true;
        }

        return false;
    }

    @Override
    public boolean equals(Object o) {
        if (o instanceof Point && ((Point) o).getX() == x && ((Point) o).getY() == y) {
            return true;
        }
        return false;
    }

    @Override
    public String toString() {
        return "(" + x + ", " + y + ")";
    }

}
